feat(c/db2): add initial connection-only Db2 driver#4286
feat(c/db2): add initial connection-only Db2 driver#4286nishantchandraa wants to merge 1 commit intoapache:mainfrom
Conversation
Introduce the IBM DB2 C/C++ driver skeleton with connection lifecycle support, option parsing, and connection-level error handling to establish a small, reviewable baseline. Add focused connection-flow tests and minimal build/docs wiring while deferring execution and metadata APIs to follow-up work.
|
I’d really appreciate your feedback on this initial DB2 ADBC driver PR. This change is intentionally scoped to connection management only, so we can align early on structure and approach before expanding further. Specifically, I’d love feedback on: Overall driver structure and integration with the existing ADBC C/C++ layout If this direction looks good, I plan to follow up with smaller PRs for: statement execution Please let me know if you’d prefer this to be split further or structured differently. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR adds the first C/C++ ADBC driver skeleton for IBM Db2, scoped to connection management so the codebase can land a narrow baseline before execution and metadata support are added later. It extends the existing ADBC C/C++ driver set with build wiring, Db2-specific connection handling, and initial docs/tests.
Changes:
- Adds a new
c/driver/db2driver with database/connection lifecycle, option parsing, and SQLSTATE-to-ADBC error mapping. - Wires the Db2 driver into CMake/CI/docs and adds package metadata/public headers.
- Adds connection-focused tests covering lifecycle, validation, precedence, and selected failure modes.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/source/index.rst | Adds the Db2 driver page to the docs index. |
| docs/source/driver/db2.rst | Introduces end-user Db2 driver documentation. |
| ci/scripts/cpp_test.sh | Adds Db2 test label selection to C++ test script. |
| c/include/arrow-adbc/driver/db2.h | Adds the public Db2 driver C header and options. |
| c/driver/db2/statement.h | Adds the initial Db2 statement stub. |
| c/driver/db2/README.md | Adds driver-local build/testing notes. |
| c/driver/db2/meson.build | Adds Meson build metadata for the Db2 driver. |
| c/driver/db2/error.h | Declares Db2 error helpers and SQLSTATE mapping. |
| c/driver/db2/error.cc | Implements diagnostic extraction and status mapping. |
| c/driver/db2/db2.cc | Exposes the driver entrypoints and ADBC trampolines. |
| c/driver/db2/db2_test.cc | Adds Db2 connection and option tests. |
| c/driver/db2/db2_odbc.h | Adds the shared Db2 CLI/ODBC include wrapper. |
| c/driver/db2/database.h | Declares the Db2 database object and state. |
| c/driver/db2/database.cc | Implements environment setup, options, and connection-string building. |
| c/driver/db2/connection.h | Declares the Db2 connection object. |
| c/driver/db2/connection.cc | Implements connect/disconnect and default autocommit setup. |
| c/driver/db2/CMakeLists.txt | Adds CMake build/test/package wiring for the driver. |
| c/driver/db2/AdbcDriverDb2Config.cmake.in | Adds CMake package config template for the driver. |
| c/driver/db2/adbc-driver-db2.pc.in | Adds pkg-config metadata for the driver. |
| c/CMakeLists.txt | Wires the Db2 driver into the top-level C build. |
| c/cmake_modules/DefineOptions.cmake | Adds the top-level CMake build option for Db2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| db2_dep = meson.get_compiler('c').find_library('db2', required: true) | ||
|
|
||
| adbc_db2_driver_lib = library( |
| db2_dep = meson.get_compiler('c').find_library('db2', required: true) | ||
|
|
| adbc_install_python_package(snowflake) | ||
| endif() | ||
|
|
||
| if(ADBC_DRIVER_DB2) |
|
|
||
| Status Db2Database::ReleaseImpl() { | ||
| if (henv_ != SQL_NULL_HENV) { | ||
| SQLFreeHandle(SQL_HANDLE_ENV, henv_); |
| // SQLDriverConnect mutates the input string; copy to a stable buffer. | ||
| const std::string& conn_str = database_->connection_string(); | ||
| SQLCHAR out_str[1024]; | ||
| SQLSMALLINT out_len = 0; | ||
| SQLRETURN rc = SQLDriverConnect( | ||
| hdbc_, /*WindowHandle=*/nullptr, | ||
| const_cast<SQLCHAR*>(reinterpret_cast<const SQLCHAR*>(conn_str.c_str())), | ||
| static_cast<SQLSMALLINT>(conn_str.size()), out_str, sizeof(out_str), &out_len, |
| subsequent pull requests. Calling those entry points returns | ||
| ``ADBC_STATUS_NOT_IMPLEMENTED``. |
| if (GetTestUri() == nullptr) { | ||
| GTEST_SKIP() << "ADBC_DB2_TEST_URI not set"; | ||
| } |
Summary
This PR introduces an initial C/C++ ADBC driver for IBM Db2, intentionally scoped to connection management only so maintainers can review a small, focused baseline.
Included in this PR
SQLHENVmanagement)SQLHDBCallocation, connect, disconnect)urisupportusername/passwordsynonymsurioverrides conflicting per-field options1-65535required)Explicitly out of scope
GetInfo,GetObjects, schemas/catalog)Validation
Tested against a live Db2 instance on
localhost:50000:adbc-driver-db2-test: 15/15 passedctest -L driver-db2: passCoverage includes:
uriprecedence over per-field optionsNotes for reviewers
This PR is intentionally narrow to establish a clean, reviewable baseline for DB2 support in ADBC. Follow-up PRs will add statement execution, metadata, transaction functionality, and broader feature parity incrementally.